package com.zhuss.core.menu;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zhuss.bean.bo.core.resource.CreateResourceBo;
import com.zhuss.bean.bo.core.resource.DeleteResourceBo;
import com.zhuss.bean.bo.core.resource.ResourcePermissionBindBo;
import com.zhuss.bean.bo.core.resource.UpdateResourceBo;
import com.zhuss.common.OperateService;
import com.zhuss.common.Processor;
import com.zhuss.exception.AabException;


/**
 * 菜单资源点操作service（基本操作）
 * @author zhushanshuo
 * @Date 2019-12-13 15:59
 *
 */
@Component("resourceOperateService")
public class ResourceOperateService implements OperateService<Void, Object> {
	
	@Autowired
	@Qualifier("resourceCreate")
	private Processor<Object, CreateResourceBo> resourceCreate;
	
	@Autowired
	@Qualifier("resourceUpdate")
	private Processor<Object, UpdateResourceBo> resourceUpdate;
	
	@Autowired
	@Qualifier("resourceDelete")
	private Processor<Object, DeleteResourceBo> resourceDelete;
	
	@Autowired
	@Qualifier("resourcePermissionBind")
	private Processor<Object, ResourcePermissionBindBo> resourcePermissionBind;
	
	/**
	 * 创建
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
	public Void create(Object param) throws AabException {
		
		CreateResourceBo bo = (CreateResourceBo) param;
		
		resourceCreate.process(bo);
		
		return null;
	}
    
	/**
	 * 修改
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
    public Void update(Object param) throws AabException {
		
		UpdateResourceBo bo = (UpdateResourceBo) param;
    	
		resourceUpdate.process(bo);
		
    	return null;
    }
	
	/**
	 * 删除
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Void delete(Object param) throws AabException {
		
		DeleteResourceBo bo = (DeleteResourceBo) param;
		
		resourceDelete.process(bo);
		
		return null;
	}
	
	/**
	 * 给菜单资源绑定权限
	 * @param param
	 * @return
	 * @throws AabException
	 */
	@Transactional(rollbackFor = Exception.class)
	protected Void resourcePermissionBind(Object param) throws AabException {
		
		ResourcePermissionBindBo bo = (ResourcePermissionBindBo) param;
		
		resourcePermissionBind.process(bo);
		
		return null;
	}
	
}

